package cn.hncj.lyc.controller.front;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.hncj.lyc.bean.ConsigneeManagement;
import cn.hncj.lyc.bean.UserInfo;
import cn.hncj.lyc.service.ConsigneeManagementService;

/**
 * 收货人信息的控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/")
public class ConsigneeConsigneeController {
	@Autowired
	private ConsigneeManagementService cmservice;
	
	
	/*
	 * 选着收货人
	 */
	@RequestMapping("SelectConsigneeList")
	public String SelectConsigneeList() {
		return "front/consignee_index";
	}
	
	

	/**
	 * 查询收货人
	 * 
	 * @param session
	 * @param cm
	 * @param model
	 * @return
	 */
	@RequestMapping("ConsigneeList")
	public String getInfo(HttpSession session, ConsigneeManagement cm, Model model) {

		UserInfo user = (UserInfo)session.getAttribute("loginuser");
		if(cm == null){
			cm = new ConsigneeManagement();
		}
		cm.setUserId(user.getUserId());
		List<ConsigneeManagement> ccmlist =cmservice.getInfo(cm);
		model.addAttribute("ccmlist", ccmlist);
		

		return "front/consignee_list";
	}
	
	/**
	 * 添加
	 * @param session
	 * @param cm
	 * @param model
	 * @return
	 */
	@RequestMapping("ConsigneeAdd")
	public String add(HttpSession session, ConsigneeManagement cm, Model model){
		UserInfo user = (UserInfo)session.getAttribute("loginuser");
		if(cm == null){
			cm = new ConsigneeManagement();
		}
		cm.setUserId(user.getUserId());
		
		try {
			cmservice.add(cm);
			
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("info", "添加失败!");
		}
		
		
		
		return "front/consignee_index";
	}
	

	
	/**
	 * 修改
	 * @param session
	 * @param cm
	 * @param model
	 * @return
	 */
	@RequestMapping("ConsigneeUpdate")
	public String update(HttpSession session, ConsigneeManagement cm, Model model){
		UserInfo user = (UserInfo)session.getAttribute("loginuser");
		if(cm == null){
			cm = new ConsigneeManagement();
		}
		cm.setUserId(user.getUserId());
		
		try {
			cmservice.update(cm);
			
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("info", "修改失败!");
		}
		
		return "front/consignee_index";
	}
	
	
	/**
	 * 修改
	 * @param session
	 * @param cm
	 * @param model
	 * @return
	 */
	@RequestMapping("ConsigneeDelete")
	public String delete(HttpSession session, ConsigneeManagement cm, Model model){
		UserInfo user = (UserInfo)session.getAttribute("loginuser");
		if(cm == null){
			cm = new ConsigneeManagement();
		}
		cm.setUserId(user.getUserId());
		
		try {
			cmservice.delete(cm);
			
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("info", "删除失败!");
		}
		
		return "front/consignee_index";
	}


}
